package cn.wbnyua.msm.web.api;

import cn.wbnyua.msm.core.exception.ForbiddenException;
import cn.wbnyua.msm.util.JsonResponse;
import cn.wbnyua.msm.util.JwtToken;
import cn.wbnyua.msm.web.domain.SysUser;
import cn.wbnyua.msm.web.service.RedisService;
import cn.wbnyua.msm.web.service.SysUserService;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 作者：wbnyua.
 * 创建时间: 2023/2/9 12:03.
 */

@RestController
@RequestMapping("/user")
@Validated
public class UserApi {

    @Autowired
    private SysUserService service;

    @Autowired
    RedisService redisService;

//    @Autowired
//    private ProducerSchedule producer;

    @GetMapping
    public JsonResponse<String> getToken() {
        String token = JwtToken.makeToken(123L, 1);

//        producer.send("TopicTest","test","text");
        redisService.sendToRedis(1L,123L,1L);
        return new JsonResponse<>(token);
    }

    @PostMapping
    public JsonResponse<String> login(@RequestBody @Validated SysUser user) {
        String token = service.login(user);
        return new JsonResponse<>(token);
    }

    @DeleteMapping("/{id}")
    public JsonResponse<String> remove(@PathVariable("id") @Range(min = 1,max = 10,message = "1~10之间") Integer id){
        System.out.println(id);
        return JsonResponse.success();
    }


}
